class Dequeue {
    constructor () {
      this.count = 0
      this.lowestCount = 0
      this.items = {}
    }
    size () {
      return this.count - this.lowestCount
    }
    isEmpty () {
      return this.size() === 0
    }
    clear () {
      this.count = 0
      this.lowestCount = 0
      this.items = {}
    }
    toString () {
      if (this.isEmpty()) {
        return ''
      }
      let strObj = this.items[this.lowestCount]
      for (let i = this.lowestCount + 1; i < this.count; i++) {
        strObj = `${strObj},${this.items[i]}`
      }
      return strObj
    }
    addFront (element) {
      if (this.isEmpty()) {
        this.addBack(element)
      } else {
        this.items[--this.lowestCount] = element
      }
    }
    addBack (element) {
      this.items[this.count] = element
      this.count++
    }
    removeFront () {
      if (this.isEmpty()) {
        return undefined
      }
      const result = this.items[this.lowestCount]
      delete this.items[this.lowestCount]
      this.lowestCount++
      return result
    }
    removeBack () {
      if (this.isEmpty()) {
        return undefined
      }
      this.count--
      const result = this.items[this.count]
      delete this.items[this.count]
      return result
    }
    peekFront () {
      if (this.isEmpty()) {
        return undefined
      }
      return this.items[this.lowestCount]
    }
    peekBack () {
      if (this.isEmpty()) {
        return undefined
      }
      return this.items[this.count - 1]
    }
}


function huiwenjianchaqi(string){
    // 输入验证
    if (string === undefined || string === null || string === "") {
        return false;
    }
    const dequeue=new Dequeue()
    let front,back

    for (let i = 0; i < string.length; i++) {
        dequeue.addBack(string.charAt(i))//返回字符串中指定索引（下标）处的字符
      }

    while (dequeue.size() > 1) {
          front = dequeue.removeFront();
          back = dequeue.removeBack();
          if (front !== back) {
               return false; // 不相等则不是回文
        }
    }
    return true//相等是回文
}
console.log(huiwenjianchaqi('adda'));